import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;


public class TestTrip {
	private int numberOfStudents[] = {3, 4};
	private double moneyList[][] = {
			{10.00,20.00,30.00},
			{15.00,15.01,3.00,3.01},
	};
	private double result[] = {10.00, 11.99};
	double mean[] = {20.00, 9.00};
	
	private Trip generateInitTrip(int index) {
		Trip trip = new Trip(numberOfStudents[index]);
		try {
			for(int i = 0; i < numberOfStudents[index]; ++i) {
				trip.addMoney(moneyList[index][i]);
			}
		}catch (Exception e) {
			assertTrue(false);
		}
		return trip;
	}

	@Test
	public void testNumberOfStudents() {
		int testcaseIndex = 0;
		Trip trip = new Trip(numberOfStudents[testcaseIndex]);
		assertEquals(numberOfStudents[testcaseIndex], trip.getNumberOfStudents());		
	}
	
	@Test
	public void testAddMoney() {
		int testcaseIndex = 0;
		Trip trip = generateInitTrip(testcaseIndex);
		
		double[] moneyArray = trip.getMoneyList();
		
		assertEquals(numberOfStudents[testcaseIndex], moneyArray.length);
		assertFalse(moneyArray[0] == 40.00);		
		for(int i = 0; i < numberOfStudents[testcaseIndex]; ++i) {
			assertTrue(moneyArray[i] == moneyList[testcaseIndex][i]);
		}
				
		try{			
			trip.addMoney(40.00);
			assertTrue(false);
			trip.addMoney(50.00);		
			assertTrue(false);
		} catch(Exception e) {
			assertTrue(true);
		}		
	}
	
	@Test
	public void testCalculateMean() {
		for(int i = 0; i < numberOfStudents.length; ++i) {
			Trip trip = generateInitTrip(i);
			double result = Trip.calculateMean(trip.getMoneyList());
			assertTrue("Test Case : " + i + ", Result : " + result,
					mean[i] == result );
		}
	}
		
	@Test
	public void testCalculateMinSpiltMoney() {		
		for(int i = 0; i < numberOfStudents.length; ++i) {
			Trip trip = generateInitTrip(i);
			try {
				double spiltMoney = trip.getMeanSpiltMoney();
				assertTrue("Test Case : " + i + ", Result : " + spiltMoney 
						, result[i] == spiltMoney);
			}catch (Exception e) {
				assertTrue("Test Case : " + i, false);
			}
		}
	}

}
